import { queryRuleHome,queryRule, removeRule, addRule } from '../services/api';
import { message } from 'antd';

export default {
  namespace: 'home',

  state: {
      // result: [],
      list: [],
      loading: false,
  },

  effects: {
  
    *fetch({ payload ,callback}, { call, put }) {

      yield put({
        type: 'save',
        payload: {
          loading: true,
        },
      });

      const response = yield call(queryRuleHome, payload);
      
      if(response.result.code != 200){
        message.error(response.result.message) 
      }
      if(response.data){
        yield put({
          type: 'save',
          payload: {
            list: response.data,
            loading: false,
          },
        });
      } 
      if(callback)callback(); 
    },
  },

  reducers: {//纯函数， 输入什么输出就是什么
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};
